package com.xuecheng.media.api;


import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.model.dto.MediaFilesUploadResultDto;
import com.xuecheng.content.model.dto.QueryMediaParamsDto;
import com.xuecheng.content.model.dto.TeachplanAndTMediaAndMediaFileDto;
import com.xuecheng.content.model.po.MediaFiles;
import com.xuecheng.media.service.MediaFilesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@Api(value = "媒体文件信息管理", tags = "媒体文件信息管理接口")
public class MediaFilesUploadController {

    @Autowired
    private MediaFilesService mediaFilesService;
    @ApiOperation("媒资列表查询接口")
    @PostMapping("/files")
    public PageResult<MediaFiles> list(PageParams pageParams, @RequestBody QueryMediaParamsDto queryMediaParamsDto){
        Long companyId = 1232141425L;
        return mediaFilesService.queryMediaFiels(companyId,pageParams,queryMediaParamsDto);

    }

    @ApiOperation("文件上传")
    @PostMapping("/upload/coursefile")
    public MediaFilesUploadResultDto uploadFile(@ApiParam(value = "课程ID", required = true) @RequestParam("courseId") Long courseId, @ApiParam(value = "上传的文件",required = true)@RequestPart("filedata")MultipartFile file) {

        log.info("接收到课程ID: {}", courseId);
        // 验证文件字段
        if (file == null || file.isEmpty()) {
            throw new RuntimeException("未收到文件数据");
        }

        Boolean result = mediaFilesService.deleteUploadImageCourseBase(courseId);
        return mediaFilesService.uploadFilesCourseBase(file,courseId);
    }

    @ApiOperation("文件上传")
    @PostMapping("/upload/courseTeacherFile")
    public MediaFilesUploadResultDto uploadCourseTeacherFile( @ApiParam(value = "教师ID", required = true) @RequestParam("teacherId") Long teacherId,@ApiParam(value = "上传的文件",required = true)@RequestPart("filedata")MultipartFile file) {

        log.info("接收到教师ID: {}", teacherId);
        // 验证文件字段
        if (file == null || file.isEmpty()) {
            throw new RuntimeException("未收到文件数据");
        }

        Boolean result = mediaFilesService.deleteUploadImageCourseTeacher(teacherId);
        return mediaFilesService.uploadFilesCourseTeacher(file,teacherId);
    }

    @ApiOperation("文件删除")
    @DeleteMapping("/deleteFiles/{fileId}")
    public void deleteFile(@PathVariable String fileId){
        mediaFilesService.deleteMinioById(fileId);
    }

    @ApiOperation("课程大纲资源文件上传")
    @PostMapping("/upload/CourseOutlineNode/resourse")
    public TeachplanAndTMediaAndMediaFileDto uploadCourseOutlineNode(@ApiParam(value="上传的文件",required = true)@RequestPart("filedata") MultipartFile file, @ApiParam(value = "教师ID", required = true) @RequestParam("teacherId") Long teacherId){
        return mediaFilesService.uploadCourseOutlineNode(file,teacherId);
    }


}




































